package vista;
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;


/**
 * This code was edited or generated using CloudGarden's Jigloo
 * SWT/Swing GUI Builder, which is free for non-commercial
 * use. If Jigloo is being used commercially (ie, by a corporation,
 * company or business for any purpose whatever) then you
 * should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details.
 * Use of Jigloo implies acceptance of these licensing terms.
 * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
 * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
 * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class VentanaCorte extends javax.swing.JFrame {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JPanel pnlCorte;
	private JLabel lblCategoria;
	private JLabel lblBs;
	private JTextField txtPrecio;
	private JLabel lblPrecio;
	private JButton btnBuscar;
	private JButton btnCancelar;
	private JButton btnLimpiar;
	private JButton btnEliminar;
	private JButton btnModificar;
	private JButton btnGuardar;
	private JComboBox cmbCategoria;
	private JTextField txtDescripcion;
	private JTextField txtCodigoCorte;
	private JLabel lblDescripcion;
	private JLabel lblCodigoCorte;
	private JLabel lblRegistroCortes;

	/**
	 * Auto-generated main method to display this JFrame
	 */


	private static VentanaCorte instancia;

	public static  VentanaCorte getInstancia() {
		if (instancia == null){
			instancia = new VentanaCorte();
		}
		return instancia;
	}








	public void agregarListener(ActionListener accion){

		btnGuardar.addActionListener(accion);
		btnModificar.addActionListener(accion);
		btnEliminar.addActionListener(accion);
		btnCancelar.addActionListener(accion);
		btnBuscar.addActionListener(accion);
		btnLimpiar.addActionListener(accion);
	}



	//SET Y GET DE LOS BOTONES
	public JButton getBtnCancelar() {
		return btnCancelar;
	}

	public void setBtnCancelar(JButton btnCancelar) {
		this.btnCancelar = btnCancelar;
	}

	public JButton getBtnLimpiar() {
		return btnLimpiar;
	}

	public void setBtnLimpiar(JButton btnLimpiar) {
		this.btnLimpiar = btnLimpiar;
	}

	public JButton getBtnEliminar() {
		return btnEliminar;
	}

	public void setBtnEliminar(JButton btnEliminar) {
		this.btnEliminar = btnEliminar;
		btnEliminar.setEnabled(false);
	}
	public JButton getBtnModificar() {
		return btnModificar;
	}
	public void setBtnModificar(JButton btnModificar) {
		this.btnModificar = btnModificar;
		btnModificar.setEnabled(false);
	}

	public JButton getBtnGuardar() {
		return btnGuardar;
	}

	public void setBtnGuardar(JButton btnGuardar) {
		this.btnGuardar = btnGuardar;
	}

	public void setBtnBuscar(JButton btnBuscar) {
		this.btnBuscar = btnBuscar;
	}


	//SET Y GET DE LOS CAMPOS
	public void setCodigoCorte(String cod){
		txtCodigoCorte.setText(cod);
	}

	public String getCodigoCorte(){
		return txtCodigoCorte.getText();
	}


	public void setDescripcion(String desc){
		txtDescripcion.setText(desc);
	}

	public String getDescripcion(){
		return txtDescripcion.getText();
	}

	public void setCategoria(String cat){
		cmbCategoria.setSelectedItem(cat);
	}

	public String getCategoria(){	
		return cmbCategoria.getSelectedItem().toString();
	}

	public void setPrecio(float precio){
		txtPrecio.setText(String.valueOf(precio));
	}

	public float getPrecio(){
		return Float.valueOf(txtPrecio.getText());
	}




	public void setCategoriaComboBox(ArrayList<String> nombre){
		cmbCategoria.removeAllItems();
		cmbCategoria.addItem("Seleccione categoria");
		for(int i = 0; i < nombre.size();i++)
			cmbCategoria.addItem(nombre.get(i));

	}

	public void limpiarCampos(){
		txtCodigoCorte.setText("");
		txtDescripcion.setText("");
		txtPrecio.setText("");
	}
	
	
	public void habilitarCampos(boolean v){
		txtDescripcion.setEnabled(v);
		txtPrecio.setEnabled(v);
		cmbCategoria.setEnabled(v);
		
	}
	
	
	
	//BLOQUEAR BOTONES
	public void habilitarBotones(boolean v){
		btnEliminar.setEnabled(v);
		btnModificar.setEnabled(v);
		
	}


	public void mostrarMensaje(String mensaje) {
		JOptionPane.showMessageDialog(this, mensaje);
	}

	public Boolean validar(){

		if (txtCodigoCorte.getText().isEmpty()== true){
			mostrarMensaje("Ingrese el codigo");		
			return false;
		}
		else
			if(txtDescripcion.getText().isEmpty()== true){
				mostrarMensaje("Ingrese la descripcion")	;
				return false;
			}	
			else
				if(cmbCategoria.getActionCommand().isEmpty() == true){
					mostrarMensaje("Seleccione categoria");
					return false;
				}
				else
					return true;
	}

	public VentanaCorte() {
		super();
		initGUI();
	}

	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			this.setTitle("Cortes");
			getContentPane().setLayout(null);
			{
				pnlCorte = new JPanel();
				getContentPane().add(pnlCorte, "Center");
				pnlCorte.setLayout(null);
				pnlCorte.setBounds(0, 0, 507, 343);
				pnlCorte.setBackground(new java.awt.Color(255,255,255));
				{
					lblRegistroCortes = new JLabel();
					pnlCorte.add(lblRegistroCortes);
					lblRegistroCortes.setText("Registro de Cortes");
					lblRegistroCortes.setBounds(187, 32, 136, 15);
					lblRegistroCortes.setFont(new java.awt.Font("Dialog",1,14));
				}
				{
					lblCodigoCorte = new JLabel();
					pnlCorte.add(lblCodigoCorte);
					lblCodigoCorte.setText("Codigo de Corte: ");
					lblCodigoCorte.setBounds(55, 83, 114, 15);
				}
				{
					lblDescripcion = new JLabel();
					pnlCorte.add(lblDescripcion);
					lblDescripcion.setText("Descripcion: ");
					lblDescripcion.setBounds(55, 122, 89, 15);
				}
				{
					lblCategoria = new JLabel();
					pnlCorte.add(lblCategoria);
					lblCategoria.setText("Categoria: ");
					lblCategoria.setBounds(55, 171, 69, 15);
				}
				{
					txtCodigoCorte = new JTextField();
					pnlCorte.add(txtCodigoCorte);
					txtCodigoCorte.setBounds(175, 79, 71, 19);
				}
				{
					txtDescripcion = new JTextField();
					pnlCorte.add(txtDescripcion);
					txtDescripcion.setBounds(175, 118, 141, 22);
				}
				{
					ComboBoxModel cmbCategoriaModel = 
							new DefaultComboBoxModel(
									new String[] { "Item One", "Item Two" });
					cmbCategoria = new JComboBox();
					pnlCorte.add(cmbCategoria);
					cmbCategoria.setModel(cmbCategoriaModel);
					cmbCategoria.setBounds(175, 167, 141, 22);
				}
				{
					btnGuardar = new JButton();
					pnlCorte.add(btnGuardar);
					btnGuardar.setText("Guardar");
					btnGuardar.setBounds(12, 283, 88, 22);
				}
				{
					btnModificar = new JButton();
					pnlCorte.add(btnModificar);
					btnModificar.setText("Modificar");
					btnModificar.setBounds(118, 283, 87, 22);
				}
				{
					btnEliminar = new JButton();
					pnlCorte.add(btnEliminar);
					btnEliminar.setText("Eliminar");
					btnEliminar.setBounds(216, 283, 91, 22);
				}
				{
					btnLimpiar = new JButton();
					pnlCorte.add(btnLimpiar);
					btnLimpiar.setText("Limpiar");
					btnLimpiar.setBounds(323, 283, 77, 22);
				}
				{
					btnCancelar = new JButton();
					pnlCorte.add(btnCancelar);
					pnlCorte.add(getBtnBuscar());
					pnlCorte.add(getLblPrecio());
					pnlCorte.add(getTxtPrecio());
					pnlCorte.add(getLblBs());
					btnCancelar.setText("Cancelar");
					btnCancelar.setBounds(411, 283, 85, 22);
				}
			}
			pack();
			this.setSize(517, 373);
		} catch (Exception e) {
			//add your error handling code here
			e.printStackTrace();
		}
	}

	private JButton getBtnBuscar() {
		if(btnBuscar == null) {
			btnBuscar = new JButton();
			btnBuscar.setText("Buscar");
			btnBuscar.setBounds(258, 78, 77, 22);
		}
		return btnBuscar;
	}

	private JLabel getLblPrecio() {
		if(lblPrecio == null) {
			lblPrecio = new JLabel();
			lblPrecio.setText("Precio por Kg : ");
			lblPrecio.setBounds(55, 229, 108, 15);
		}
		return lblPrecio;
	}

	private JTextField getTxtPrecio() {
		if(txtPrecio == null) {
			txtPrecio = new JTextField();
			txtPrecio.setBounds(175, 225, 52, 22);
		}
		return txtPrecio;
	}

	private JLabel getLblBs() {
		if(lblBs == null) {
			lblBs = new JLabel();
			lblBs.setText("Bs.");
			lblBs.setBounds(231, 229, 34, 15);
		}
		return lblBs;
	}

}
